﻿
using JshRCSWebApi.Infrastructure.Domain.DTO.SysService;
using Org.BouncyCastle.Tsp;
using ZstdSharp.Unsafe;

public class RoleController : BaseController
{
    private readonly RoleService _roleService;

    public RoleController(IHttpContextAccessor httpContextAccessor, RoleService roleService) : base(httpContextAccessor)
    {
        this._roleService = roleService;
    }

    /// <summary>
    /// 获取角色列表(分页展示表格)
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> GetRoleList([FromBody] RoleSearchDTO searchDTO)
        => await Task.Run(async () => ApiResult.Success("获取成功", await _roleService.GetRoleList(searchDTO)));

    /// <summary>
    /// 获取角色名称和ID集合
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResult> GetRoleNameAndIDList(int ID)
        => await Task.Run(async () => await _roleService.GetRoleNameAndIDList(ID));

    /// <summary>
    /// 新增角色
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> AddRole([FromBody] RoleAddDTO roleDTO)
        => await Task.Run(async () => await _roleService.AddRole(roleDTO, Convert.ToInt32(GetUser("ID"))));

    /// <summary>
    /// 修改角色
    /// </summary>
    /// <param name="roleDTO"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> UpdateRole([FromBody] RoleUpdateDTO roleDTO)
        => await Task.Run(async () => await _roleService.UpdateRole(roleDTO, Convert.ToInt32(GetUser("ID"))));

    /// <summary>
    /// 删除角色
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    [HttpDelete]
    public async Task<ApiResult> DeleteRole(int ID)
       => await Task.Run(async() => await _roleService.DeleteRole(ID));

    /// <summary>
    /// 修改角色权限
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResult> UpdateUserJurisdiction([FromBody] RoleUpdateJurisdiction updateDto)
        => await Task.Run(async() => await _roleService.UpdateUserJurisdiction(updateDto, Convert.ToInt32(GetUser("ID"))));
}

